/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Interface.InterfaceLastName;
import Pojo.Lastname;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author knyazev_o
 */
public class DaoLastName implements InterfaceLastName{

    @Override
    public boolean register(Session session, Lastname lastName) throws Exception {
        session.save(lastName);        
        return true;
    }

    @Override
    public List<Lastname> getAll(Session session) throws Exception {
        String hql="from Lastname";
        Query query=session.createQuery(hql);        
        List<Lastname> listLastName =(List<Lastname>) query.list();        
        return listLastName;
    }

    @Override
    public boolean update(Session session, Lastname lastName) throws Exception {
        session.update(lastName);
        return true;
    }

    @Override
    public boolean delete(Session session, Lastname lastName) throws Exception {
        session.delete(lastName);
        return true;
    } 

    @Override
    public Lastname selectLastName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }
        Lastname lastName=(Lastname) query.uniqueResult();        
        return lastName;
    }

    @Override
    public List<Lastname> selectListLastName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }       
        List<Lastname> listLastName =(List<Lastname>) query.list();        
        return listLastName;
    }
    
}
